<template>
	<view class="user_content">
		<view class="config_user" @click="go_user_config">
			<image src="../../static/manhua/set.png" style="width: 25px;height: 25px;"></image>
		</view>
		<view class="user_container">
			<view class="user_headimg">
				<view class="headimg">
					<image :src="headImg" style="width: 100%;height: 100%;border-radius: 50%;"></image>
				</view>
				<view class="username">
					{{username}}
				</view>
			</view>
			<view>
				<view class="user_cartoon">
					<u-subsection
					:list="list"
					:current="current"
					activeColor="black"
					inactiveColor="gray"
					@change="sectionChange"
					></u-subsection>
				</view>
				<view class="user_love" v-if="current==0">
					<view class="love_title">
						<view class="title_left">
							<view class="title_divi">
							</view>
							<view style="float:left;padding-left: 8px;font-size: 15px;">
								我的收藏
							</view>
						</view>
						<view class="title_right">
							<image src="../../static/right_icon.png" style="width: 100%;height: 100%;"></image>
						</view>
					</view>
					<view class="love_list" v-if="LovemanhuaList[0]">
						<u-loading-page :loading="loading1" bg-color="gray"></u-loading-page>
						<ManhuaItem v-for="manhua in LovemanhuaList" :key="manhua.id" :manhua="manhua"></ManhuaItem>
					</view>
					<view class="love_list" v-else>
						<u-empty
						    mode="list"
						    icon="http://cdn.uviewui.com/uview/empty/list.png"
							text="暂无收藏内容"
						>
						</u-empty>
					</view>
					
					<view class="love_title">
						<view class="title_left">
							<view class="title_divi">
							</view>
							<view style="float:left;padding-left: 8px;font-size: 15px;">
								浏览历史
							</view>
						</view>
						<view class="title_right" @click="showmanhualove">
							<image src="../../static/right_icon.png" style="width: 100%;height: 100%;"></image>
						</view>
					</view>
					<view class="love_list" v-if="HistorymanhuaList[0]">
						<u-loading-page :loading="loading2" bg-color="gray"></u-loading-page>
						<ManhuaItem v-for="manhua in HistorymanhuaList" :key="manhua.id" :manhua="manhua"></ManhuaItem>
					</view>
					<view class="love_list" v-else>
						<u-empty
						    mode="list"
						    icon="http://cdn.uviewui.com/uview/empty/list.png"
							text="暂无浏览历史"
						>
						</u-empty>
					</view>
				</view>
				<view class="essay_love" v-if="current==1">
					<view class="love_title">
						<view class="title_left">
							<view class="title_divi">
							</view>
							<view style="float:left;padding-left: 8px;font-size: 15px;">
								我的文章
							</view>
						</view>
						<view class="title_right">
							<image src="../../static/right_icon.png" style="width: 100%;height: 100%;"></image>
						</view>
					</view>
					<view class="essay_list" v-if="essayList[0]">
						<!-- <u-loading-page :loading="loading1" bg-color="gray"></u-loading-page> -->
						<EssayItem v-for="essay in essayList" :key="essay.essayId" :essay="essay" :myessay="true"></EssayItem>
					</view>
					<view class="love_list" v-else>
						<u-empty
						    mode="list"
						    icon="http://cdn.uviewui.com/uview/empty/list.png"
							text="暂无发表的文章"
						>
						</u-empty>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api/config.js'
	import ManhuaItem from '../../components/manhuaItem.vue'
	import EssayItem from '../../components/essayItem.vue'
	export default {
		data() {
			return {
				list: ['漫画', '文章'],
				current: 0,
				username: '',
				headImg: '',
				LovemanhuaList: [],
				HistorymanhuaList: [],
				loading1: true,
				loading2: true,
				essayList: []
			}
		},
		components: {
			ManhuaItem,
			EssayItem
		},
		methods: {
			sectionChange(val){
				this.current = val
			},
			go_user_config() {
				uni.navigateTo({
					url:'/pages/user_config/user_config'
				})
			}
		},
		mounted() {
			this.username = uni.getStorageSync('username')
			this.headImg = api + '/static/headImg/' + this.username + '.png'
			let mobile = uni.getStorageSync('mobile')
			uni.request({
				url:api + '/get_love/',
				method:'POST',
				data:{
					username:mobile,
					cartoonId: 10010
				},
				success:res=> {
					this.LovemanhuaList = res.data.data_love
					this.loading1 = false
				}
			})
			uni.request({
				url:api + '/get_history/',
				method:'POST',
				data:{
					username:mobile
				},
				success:res=> {
					this.HistorymanhuaList = res.data.data_history
					this.HistorymanhuaList = this.HistorymanhuaList.reverse()
					this.loading2 = false
				}
			})
			uni.request({
				url:api + '/get_user_essay/',
				method:'POST',
				data:{
					essayAuthor: this.username,
				},
				success:res=>{
					this.essayList = res.data.data
				}
			})
		}
	}
</script>

<style>
.config_user{
	position: absolute;
	top: 60px;
	right: 15px;
}
.user_content{
	padding-top: 300px;
	background-image: url('../../static/userBck.png');
	/* background-size: cover; */
	background-repeat: no-repeat;
	background-attachment: fixed;
}
.user_container{
	width: 100%;
	height: 100vh;
	border-radius: 20px;
	background-color: white;
	z-index: 999;
}
.user_headimg{
	width: 100%;
	height: 70px;
	/* background-color: red; */
	padding: 0 20px 0 30px;
	position: relative;
	top: -15px;
	display: flex;
	justify-content: flex-start;
}
.headimg{
	width: 70px;
	height: 100%;
}
.username{
	height: 100%;
	font-size: 17px;
	padding-top: 22px;
	margin-left: 15px;
}
.user_cartoon{
	width: 150px;
	margin: auto;
	margin-top: 30px;
}
.user_love{
	padding: 10px;
}
.love_title{
	padding: 5px;
	display: flex;
	justify-content: space-between;
}
.title_divi{
	width: 5px;
	height: 12px;
	margin-top: 4.5px;
	border-radius: 25%;
	background-color: deepskyblue;
	float: left;
}
.title_right{
	width: 15px;
	height: 15px;
}
.love_list{
	margin-top: 5px;
	display: flex;
	justify-content: flex-start;
	white-space:nowrap;
	overflow-x:auto;
}
.essay_love{
	padding: 0 10px 10px 10px;
	margin-top: 10px;
	background-color: rgb(245, 245, 245);
}
.essay_list{
	/* margin-top: 5px; */
}
</style>
